package com.group.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.group.entity.ProjectInside;
import com.group.mapper.ProjectInsideMapper;
import com.group.service.ProjectInsideService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 朋心合力
 * @since 2021-08-09
 */
@Service
public class ProjectInsideServiceImpl extends ServiceImpl<ProjectInsideMapper, ProjectInside> implements ProjectInsideService {
    @Autowired
    private ProjectInsideMapper psm;
    //下面两个方法要区分对比
    //通过项目id来获取组的的id
    public int selectGroupIdByProjectId(int projectId){
        QueryWrapper<ProjectInside> wrapper = new QueryWrapper<>();
        wrapper.eq("projectId",projectId).last("limit 1");
        return psm.selectOne(wrapper).getGroupId();
    }

    //通过组的编号获取某个项目
    public ProjectInside selectProjectByGroupId(int groupId){
        QueryWrapper<ProjectInside> wrapper = new QueryWrapper<>();
        wrapper.eq("groupId",groupId).last("limit 1");
        return psm.selectOne(wrapper);
    }

    //往表中添加一行信息
    public int addMessage(int projectId,String fileName,ProjectInside pro){
        ProjectInside proI = new ProjectInside();
        proI.setProjectId(projectId);
        proI.setFileName(fileName);
        proI.setProjectName(pro.getProjectName());
        proI.setGroupId(pro.getGroupId());
        proI.setDescription(pro.getDescription());
        proI.setPhotoName(pro.getPhotoName());
        return psm.insert(proI);
    }


}
